<?php

namespace App\Admin\Controllers\activity;

use App\Common\statement\CommonStatement;
use App\Models\activity\Activity;
use App\Models\activity\ActivityAdmin;
use App\Models\activity\ActivityCate;
use App\Models\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ActivityController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '试卷';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Activity());

        $grid->model()->latest();
        $grid->disableExport();
        $grid->disableCreateButton();


        $grid->column('id', __('ID'));
        $grid->column('title', __('Title'));
        $grid->column('user.name', __('Founder'));
        $grid->column('cate.name', __('Cate'));
        $grid->column('intro', __('Intro'));
        $grid->column('start_time', __('Start Time'));
        $grid->column('end_time', __('End Time'));
        $grid->column('apply_end_time', __('报名截止时间'));
        $grid->column('number', __('报名人数'));
        $grid->column('status',__('Status'))->radio(CommonStatement::examstatus);
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));
        $grid->actions(function ($actions) {

        });
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Activity::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('title', __('Title'));
        $show->field('user.name', __('Founder'));
        $show->field('cate.name', __('Cate'));
        $show->field('title', __('Title'));
        $show->field('intro', __('Intro'));
        $show->field('start_time', __('Start Time'));
        $show->field('end_time', __('End Time'));
        $show->field('apply_end_time', __('报名截止时间'));
        $show->field('number', __('报名人数'));
        $show->field('content', __('Content'))->editor();
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Activity());

        $form->column(1/3, function ($form) {
            $form->text('title',__('Title'));
            $form->text('user.name',__('Founder'))->readonly();
            $form->select('cate.id',__('Cate'))->options(
                ActivityCate::where('status', 1)->pluck('name', 'id')
            );;
            $form->text('intro',__('Intro'));
            $form->date('start_time',__('Start Time'));
            $form->date('end_time',__('End Time'));
            $form->date('apply_end_time',__('报名截止时间'));
            $form->radio('status',__('Status'))->options(CommonStatement::examstatus);
        });

        $form->column(2/3, function ($form) {
            $form->textarea('content');
        });

        $form->saving(function (Form $form) {

        });

        $form->saved(function (Form $form){

        });

        return $form;
    }
}
